<template>
  <section class="page">
    <headerbar>{{title}}</headerbar>
    <!-- <section v-if="isAllUser && tabIndex==0" class="input-wrap pdh-4 pdv-3 bg-white search">
      <input type="search" v-model="keyword" placeholder="姓名搜索">
    </section> -->

      <!--未选择成员-->
      <section class="d-scroll mgt-2" v-if="tabIndex==0">
        <section class="people-list ">
          <div @click="select(item)" v-for="item in list" class="people-item block noborder">
            <section class="people-info">
              <div class="avatar-img">
                <img src="../../../../static/images/default.jpg" alt="">
              </div>
              <!--人名-->
              <span class="name">{{item.fullname}}</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
              <!-- <span class="name">{{item.orgName}}</span> -->
            </section>
            <span class=""><span :class="{'icon-radio-checked':selectedIndexOf(item)>=0}" class="icon-radio"></span></span>
          </div>
        <p class="pdv-5"></p>
        <p class="pdv-5"></p>
        </section>
      </section>
      <section class="foot-action">
        <div class="inner">
          <span @click="checkAll()" class="text"><span :class="{'icon-radio-checked':checkedList.length==list.length}" class="icon-radio"></span> <span>&nbsp;全选</span></span>
           <!-- v-if="!isRadio && canCheck" -->
          <!-- <span  v-if="isRadio"></span> -->
          <div class="btn" @click="save()">
            <div class="default-block-btn">确定</div>
          </div>
        </div>
      </section>
  </section>
</template>


<script>
  import _ from 'lodash'
  import tools from '@/utils/tools'
  export default {
    name: 'personnelSelectionConfereeAdd',
    data () {
      return {
        keyword: '',
        list: [],
        checkedList: [],
        organizationalLifeAdd: this.$store.state.organizationalLifeAdd,
        modelName: '',
        title: '',
        // isRadio: false,
        orgLifeId: false,
        searchTipName: '姓名搜索',
        canCheck: true,
        tabIndex: 0
      }
    },
    created () {
      this.userInfo = this.$localStorage.get('userInfo')
      this.modelName = this.$route.params.modelName
      // this.isRadio = this.$route.query.isRadio === 1
      this.orgLifeId = this.$route.query.orgLifeId;

      this.loadData()
    },
    watch: {
      /* keyword (val) {
        this.meet_getAddList()
      } */
    },
    methods: {
      /* searchName (item) {
        if (this.keyword) {
          return item.userName.indexOf(this.keyword) >= 0
        }
        return true
      }, */
      /* isAllUser () {
        return this.sendOrigin != 1 && !this.$store.state.isDang
      }, */
      loadData () {
        /* if (this.$store.state['checkedList' + this.modelName]) {
          this.checkedList = this.$store.state['checkedList' + this.modelName]
        } */
        let data = {
          loginId: this.userInfo.id || '3750'
        }
          this.title = '选择人员'
            return this.meet_getAddList()
      },
      // 所有党员 meet_getAddList
      meet_getAddList () {
        let data = {
           id: "",
           orgLifeId: this.orgLifeId,
           userId: this.userInfo.id || '3750',
           userName: this.userInfo.username,
          // userName: this.keyword
        }
        this.tools.showLoading()
        this.fetchService.meet_getAddList(data).then(res => {
          this.tools.hideLoading()
          if (res.code === 0) {
            console.log(res)
            this.list = res.data
          } else {
            this.tools.tip(res.message)
          }
        })
      },
      checkAll () {
        if (this.checkedList.length === this.list.length) {
          this.checkedList = []
        } else {
          this.checkedList = [].concat(this.list)
        }
      },
      selectedIndexOf (item) {
        let index = -1
        this.checkedList.some((v, i) => {
          if (item.userId === v.userId) {
            index = i
            return false
          }
        })
        return index
      },
      select (item) {
        let index = this.selectedIndexOf(item)
        if (index >= 0) {
          this.checkedList.splice(index, 1)
        } else {
          this.checkedList.push(item)
        }
        /* if (this.isRadio) {
          this.checkedList = [item]
        } */
      },
      save () {
        let list = []
        this.checkedList.forEach((v,i) => {
          this.list.forEach((item,index) => {
            if (item.userId === v.userId) {
              var obj = {
                id: "",
                orgLifeId: this.orgLifeId,
                userId: item.userId,
                userName: item.fullname
              }
              list.push(obj)
            }
          })
        })
        let data = {
           orgLifeId: this.orgLifeId,
           userVoList: list
        }
        console.log('list',list)
        this.tools.showLoading()
        this.fetchService.meet_addParticipateUser(data).then(res => {
          this.tools.hideLoading()
          if (res.code === 0) {
            console.log(res)
            this.tools.tip("添加成功")
            tools.back()
          } else {
            this.tools.tip(res.message)
          }
        })
        
      },
      /* clickMenu (index) {
        this.tabIndex = index
      } */
    }
  }
</script>

<style scoped lang="scss">
  .search {
    input {
      height:60px;
      line-height:60px;
      font-family:dang;
      margin:0;
      font-size:14PX;
    }
  }
</style>
